/**
 * 
 */
package com.lehecai.core.search.api;

import java.util.HashMap;
import java.util.Map;


/**
 * @author hanwenda
 *
 */
public class SearchApiConstant {

	//服务名称
	public static final String API_COMMAND_INSERT = "insert";
	public static final String API_COMMAND_SELECT = "select";
	public static final String API_COMMAND_UPDATE = "update";
	public static final String API_COMMAND_DELETE = "delete";
	public static final String API_COMMAND_AGGREGATE = "aggregate";
	
	//请求主题参数
	public static final String API_PARAMETER_SERVICE = "service";
	public static final String API_PARAMETER_COMMAND = "command";
	public static final String API_PARAMETER_SERIAL = "serial";
	public static final String API_PARAMETER_BODY = "body";
	//body参数
    public static final String API_PARAMETER_INSERT_FIELD = "field";
    public static final String API_PARAMETER_INSERT_VALUE = "value";
    public static final String API_PARAMETER_INSERT_FORCE = "force";

	public static final String API_PARAMETER_FILTER = "filter";
	public static final String API_PARAMETER_FILTER_TYPE = "type";
	public static final String API_PARAMETER_FILTER_FIELD = "field";
	public static final String API_PARAMETER_FILTER_VALUE= "value";
	
	public static final String API_PARAMETER_GET = "get";
	public static final String API_PARAMETER_GET_OFFSET = "offset";
	public static final String API_PARAMETER_GET_LIMIT = "limit";
	public static final String API_PARAMETER_GET_ORDER = "order";
    public static final String API_PARAMETER_GET_ORDER_NAME = "name";
	public static final String API_PARAMETER_GET_ORDER_DESC = "desc";
    public static final String API_PARAMETER_GET_FIELD = "field";
	
	public static final String API_PARAMETER_SET = "set";
	public static final String API_PARAMETER_SET_FIELD = "field";
	public static final String API_PARAMETER_SET_VALUE = "value";
	
	//aggregate参数
	public static final String API_PARAMETER_AGGREGATE = "aggregate";
	public static final String API_PARAMETER_AGGREGATE_OPERATION = "operation";
	public static final String API_PARAMETER_AGGREGATE_TARGET = "target";
	public static final String API_PARAMETER_AGGREGATE_GROUP = "group";
	public static final String API_PARAMETER_AGGREGATE_AS = "as";
	//聚合函数
	public static final String API_AGGREGATE_COUNT = "count";
	public static final String API_AGGREGATE_MIN = "min";
	public static final String API_AGGREGATE_MAX = "max";
	public static final String API_AGGREGATE_SUM = "sum";
	public static final String API_AGGREGATE_AVERAGE = "average";
	//操作运算符
	public static final String API_OP_EQUAL = "eq";
	public static final String API_OP_LESS_EQUAL = "le";
	public static final String API_OP_GREATER_EQUAL = "ge";
	public static final String API_OP_LESS = "lt";
	public static final String API_OP_GREATER = "gt";
	
	//返回参数
	public static final String API_RETURN_STATUS = "status";
	public static final String API_RETURN_SERIAL = "serial";
	public static final String API_RETURN_BODY = "body";
    public static final String API_RETURN_BODY_TOTAL = "total";
    public static final String API_RETURN_BODY_VALUE = "value";

	public static final int API_REQUEST_TIME_OUT_DEFAULT = 10000;
	public static final int API_REQUEST_TIME_OUT_LONG = 60000;	// 默认的长超时时间

    public static final int API_REQUEST_PAGESIZE_DEFAULT = 20;

	public static final int RC_SUCCESS = 0;
	public static final int RC_FAILURE = -1;
	
	public static final String JSON = "json";
	public static final String NULL = "null";

	public static final int SERIAL_DEFAULT_INSERT = 1;
	public static final int SERIAL_DEFAULT_SELECT = 2;
	public static final int SERIAL_DEFAULT_UPDATE = 3;
	public static final int SERIAL_DEFAULT_AGGREGATE = 4;
	public static final int SERIAL_DEFAULT_DELETE = 5;
	
	//错误码		错误原因
	public static final int API_RESPONSE_CODE_ONE = 1001;    //1001	    json字符串有错误，或者json对象不满足本文所说的格式
	public static final int API_RESPONSE_CODE_TWO = 1002;    //1002		 请求中某一个或多个字段名有错误或不存在
	public static final int API_RESPONSE_CODE_THREE = 1003;  //1003		字段的值不符合要求或值的类型错误
	public static final int API_RESPONSE_CODE_FOUR = 1004;   //1004		“service”或者“command”属性有错误
	public static final int API_RESPONSE_CODE_FIVE = 1005;   //1005		过滤条件的“type”属性有错误
	public static final int API_RESPONSE_CODE_SIX = 1006;    //1006		service程序崩溃或者遇到其它故障，属于搜索服务的bug
	public static final int API_RESPONSE_CODE_SEVEN = 1007;  //1007		聚合操作中的“operation”属性有错误
	public static final int API_RESPONSE_CODE_EIGHHT = 1008; //1008		插入数据是不满足唯一性要求
	public static final int API_RESPONSE_CODE_NINE = 1009;   //1009		使用update请求时，尝试修改sharding或者unique字段

	static private Map<Integer,String> failMessage = new HashMap<Integer,String>();
	static{
		failMessage.put(API_RESPONSE_CODE_ONE, "json字符串有错误，或者json对象不满足本文所说的格式");
		failMessage.put(API_RESPONSE_CODE_TWO, "请求中某一个或多个字段名有错误或不存在");
		failMessage.put(API_RESPONSE_CODE_THREE, "字段的值不符合要求或值的类型错误");
		failMessage.put(API_RESPONSE_CODE_FOUR, "service或者command属性有错误");
		failMessage.put(API_RESPONSE_CODE_FIVE, "过滤条件的type属性有错误");
		failMessage.put(API_RESPONSE_CODE_SIX, "service程序崩溃或者遇到其它故障，属于搜索服务的bug");
		failMessage.put(API_RESPONSE_CODE_SEVEN, "聚合操作中的operation属性有错误");
		failMessage.put(API_RESPONSE_CODE_EIGHHT, "插入数据时不满足唯一性要求");
		failMessage.put(API_RESPONSE_CODE_NINE, "使用update请求时，尝试修改sharding或者unique字段");
	}

    public static String getMessage(Integer code) {
        return failMessage.get(code);
    }
}
